home *** CD-ROM | disk | FTP | other *** search
/ Robotics & Artificial Int…3 (Professional Edition) / Robotics & Artificial Intelligence Tools 2003 (Professional Edition).iso / neural network tool and application / nsinstall.exe / data1.cab / DLLCust_Files / PREPOST / EXTRACT.C < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-08  |  3.1 KB  |  87 lines

  1. // Dynamic link library implementation of a channel extractor
  2.  
  3. #include "NSDLL.h" 
  4.  
  5. /***************************/
  6. /* Activation of component */
  7. __declspec(dllexport) BOOL performPrePost(
  8.     DLLData    *instance,    // Pointer to instance data (may be NULL)
  9.     NSFloat    *input,     // Pointer to the input data
  10.     NSFloat    *output,     // Pointer to the output data
  11.     int rows,         // Number of rows of data
  12.     int cols,         // Number of cols of data
  13.     BOOL preprocessor    // Flag to indicate whether this is a preprocessor or postprocessor
  14.     )
  15. {
  16.     int i;
  17.     int fromLength = getIntParameter(instance, 2, 0);
  18.     int fromStart = getIntParameter(instance, 2, 1);
  19.     int fromStop = getIntParameter(instance, 2, 2);
  20.     int toStart = getIntParameter(instance, 3, 1);
  21.  
  22.     if (!preprocessor)
  23.         for (i=0; i<=fromStop-fromStart; i++)
  24.             output[i] = 0.0f;
  25.     for (i=0; i<=fromStop-fromStart; i++)
  26.         output[toStart+i] += input[fromStart+i];
  27.     return TRUE;
  28. }
  29.  
  30. /******************************************/
  31. /* Management of instance data (OPTIONAL) */
  32. __declspec(dllexport) DLLData *allocPrePost(
  33.     DLLData    *oldInstance,    // Pointer to the last instance if reallocating
  34.     int *rows,         // Number of rows of output data, can be changed to reflect a diffenent number for the input data
  35.     int *cols,         // Number of cols of output data, can be changed to reflect a diffenent number for the input data
  36.     BOOL preprocessor    // Flag to indicate whether this is a preprocessor or postprocessor
  37.     )
  38. {
  39.     DLLData *instance = allocDLLInstance(oldInstance);
  40.     int fromLength, toLength, fromStart, fromStop, toStart, returnMax;
  41.             
  42.     setParameterName(instance, 2, 1, "From Start", TRUE);
  43.     setIntParameter(instance, 2, 1, 0, FALSE);
  44.     setParameterName(instance, 2, 2, "From Stop", TRUE);
  45.     setIntParameter(instance, 2, 2, 0, FALSE);
  46.     setParameterName(instance, 3, 1, "To Start", TRUE);
  47.     setIntParameter(instance, 3, 1, 0, FALSE);
  48.     if (preprocessor) {
  49.         setParameterName(instance, 2, 0, "From Length", TRUE);
  50.         setIntParameter(instance, 2, 0, 1, FALSE);
  51.         returnMax = fromLength = getIntParameter(instance, 2, 0);
  52.         toLength = *rows * *cols;
  53.     } else {
  54.         setParameterName(instance, 2, 0, "To Length", TRUE);
  55.         setIntParameter(instance, 2, 0, 1, FALSE);
  56.         fromLength = *rows * *cols;
  57.         returnMax = toLength = getIntParameter(instance, 2, 0);
  58.     }
  59.     if (fromLength < 1) 
  60.         fromLength = 1;
  61.     fromStart = getIntParameter(instance, 2, 1);
  62.     if (fromStart >= fromLength) 
  63.         fromStart = fromLength - 1;
  64.     fromStop = getIntParameter(instance, 2, 2);
  65.     if (fromStop < fromStart) 
  66.         fromStop = fromStart;
  67.     if (fromStop >= fromLength) 
  68.         fromStop = fromLength - 1;
  69.     toStart = getIntParameter(instance, 3, 1);
  70.     if (toStart >= toLength) 
  71.         toStart = toLength - 1;
  72.     if (toStart > toLength - (fromStop-fromStart+1)) 
  73.         fromStop = fromStart + (toLength-toStart-1);
  74.     setIntParameter(instance, 2, 1, fromStart, TRUE);
  75.     setIntParameter(instance, 2, 2, fromStop, TRUE);
  76.     setIntParameter(instance, 3, 1, toStart, TRUE);
  77.     setIntParameter(instance, 2, 0, returnMax, TRUE);
  78.     *rows = returnMax;
  79.     *cols = 1;
  80.     return instance;
  81. }
  82.  
  83. __declspec(dllexport) void freePrePost(DLLData *instance)
  84. {
  85.     freeDLLInstance(instance); 
  86. }
  87.